package com.cy.pj.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {
    private List<String> names=new ArrayList<String>();

    @GetMapping("doAjaxGet")
    public String doAjaxGet() throws Exception{
        System.out.println("==doAjaxGet==");
        Thread.sleep(5000);
        return "Ajax Get Request Result";
    }
    @RequestMapping("doCheck")
    public String doCheck(String name){
        if(names.contains(name)){
            return "名字"+name+"已存在，请选择其他名字";
        }
            return "名字"+name+"不存在，可以注册";
    }

    @RequestMapping("doSave")
    public String doSave(String name){
        System.out.println("name="+name);
        names.add(name);
        return "save ok";
    }

}
